import requests
from bs4 import BeautifulSoup

headers = {
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36"
}
f = open("斗破苍穹.txt", "a+", encoding="utf-8")


def get_info(url):
    res = requests.get(url, headers=headers)
    res.encoding = "utf-8"
    if res.status_code == 200:
        soup = BeautifulSoup(res.text, "html.parser")
        title = soup.select("h1")
        content = soup.select("#content")
        f.writelines(title[0].get_text())
        f.writelines(content[0].get_text())
        f.writelines("\n")
    else:
        pass


if __name__ == '__main__':
    urls = ["https://www.ibswtan.com/0/425/{}.html".format(str(i)) for i in range(232391, 235587)]
    n = 0
    for url in urls:
        get_info(url)
        n += 1
        print(n)
    print("下载完成！")
